import axios from 'axios'
import type {Login, User, UserItem, Password, Article,TagEdit,Comment} from '@/api/modules/weblog'
const api='https://0159e72bfc1d.ngrok-free.app/api'
//登录
export const login = (params:Login) => {
  return axios.post(`${api}/login`, params)
}
//注册
export const loginCreate = (params:Login) => {
  return axios.post(`${api}/createUser`, params);
}
//查询所有用户
export const userList = () => {
  return axios.get(`${api}/user/all`);
}
//编辑用户
export const editUser = (params:User<UserItem>) => {
  return axios.put(`${api}/user/${params.id}`, params.data);
}
//查询单个用户
export const queryUser = (id:number) => {
  return axios.get(`${api}/user/${id}`);
}
//修改密码
export const changePassword = (params:User<Password>) => {
  return axios.put(`${api}/user/password/${params.id}`, params.data);
}
//创建标签
export const createTag = (params:string) => {
  return axios.post(`${api}/label`, {name:params});
}
//创建文章
export const createArticle=(params:Article) =>{
  return axios.post(`${api}/article`,params)
}
//获取标签
export const getTag=()=>{
  return axios.get(`${api}/queryAllLabel`)
}
//获取文章
export const getArticle = (params?: number) => {
  return axios.get(`${api}/queryAllArticle${params ? '/' + params : ''}`);
};
//修改标签
export const editTag = (params:TagEdit) => {
  return axios.put(`${api}/label/${params.id}`, {name:params.name});
}
//删除标签
export const deleteTag = (params:number) => {
  return axios.delete(`${api}/label/${params}`);
}
//创建评论
export const createComment = (params:Comment) => {
  return axios.post(`${api}/comment`, params);
}
//查询评论
export const getComment=(params:number)=>{
  return axios.get(`${api}/comment/${params}`)
}
//修改头像
export const editAvatar = (id:number,formData:FormData) => {
  return axios.put(`${api}/user/avatar/${id}`, formData);
}
